#include<stdio.h>
int main()
{
	char huowu;
	int tongdao;
	int danjia;
	int jige;
	printf("请依次输入货物(用大写字母表示)、货物所在的通道，货物的单价，摆放了几个：");
	scanf("%c %d %d %d",&huowu,&tongdao,&danjia,&jige);
	while(jige>50){
		printf("最多摆放50个货物，请重新摆放：");
		scanf("%d",&jige);
	}
	while(danjia>10){
		printf("货物的单价最多为十元，请重新输入货物单价：");
		scanf("%d",&danjia);
	}
	printf("%d：",tongdao);
	int i=0;
	while(i<jige){
		i++;
		printf("%c",huowu);
	}
	printf(" %d\n",danjia);
	int zongjia;
	int shuliang;
	int tongdao1;
	char huowu1;
	chongfugoumai:
	printf("请输入货物所在的通道、货物种类和购买的数量：");
    scanf("%d %c %d",&tongdao1,&huowu1,&shuliang);
	while(shuliang>jige){
		printf("货物总共有%d个，请重新输入购买数量：",jige);
		scanf("%d",&shuliang);
	}
	while(tongdao1!=tongdao){
		printf("通道输入错误，请重新输入：");
		scanf("%d",&tongdao1);
	}
	while(huowu!=huowu1){
		printf("货物种类'%c'输入错误，请重新输入：", huowu1);
		scanf(" %c",&huowu1);
	}
	zongjia=danjia*shuliang;
	int qian;
	int zongtouru=0;
	printf("请投入1元或2元或5元：");
	scanf("%d",&qian);
	while(qian!=1&&qian!=2&&qian!=5){
		printf("只能投入1元或2元或5元，请重新投币：");
		scanf("%d",&qian);
	}
	zongtouru=zongtouru+qian;
	while(zongtouru<zongjia){
		printf("请继续投入1元或2元或5元:");
		scanf("%d",&qian);
		while(qian!=1&&qian!=2&&qian!=5){
			printf("只能投入1元或2元或5元，请重新投币：");
			scanf("%d",&qian);
		}
		zongtouru=zongtouru+qian;
	}
	if(zongtouru>zongjia){
		printf("购买完毕，找您%d元\n",zongtouru-zongjia);
	}
	else{
		printf("购买完毕");
	}
	jige=jige-shuliang;
	int shifou;
	while(jige>0){
		printf("还剩下%d个货物，您是否继续购买,若继续购买，请输入1，若结束购买，请输入0\n",jige);
		scanf("%d",&shifou);
		if(shifou==0){
			printf("再见");
			break;
		}

		else{
			goto chongfugoumai;
		}
		
	}
	return 0;
}
